package com.demostic.demostic_test.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.internal.view.SupportMenu;

import com.accloud.cloudservice.AC;
import com.accloud.cloudservice.PayloadCallback;
import com.accloud.cloudservice.VoidCallback;
import com.accloud.service.ACDeviceDataMgr;
import com.accloud.service.ACDeviceMsg;
import com.accloud.service.ACException;
import com.accloud.service.ACMsg;
import com.accloud.service.ACObject;
import com.accloud.utils.LogUtil;
import com.badoo.mobile.util.WeakHandler;
import com.bumptech.glide.Glide;
import com.demostic.demostic_test.R;
import com.demostic.demostic_test.base.BaseActivity;
import com.demostic.demostic_test.entity.DevicePropertyInfo_;
import com.demostic.demostic_test.entity.GetMapidMap;
import com.demostic.demostic_test.entity.Point;
import com.demostic.demostic_test.entity.PropertyInfo;
import com.demostic.demostic_test.entity.RoomNameInfo;
import com.demostic.demostic_test.entity.TimeAreaInfo;
import com.demostic.demostic_test.ui.MapView901;
import com.demostic.demostic_test.ui.PopupWindowWithMask;
import com.demostic.demostic_test.utils.DataUtils;
import com.demostic.demostic_test.utils.DeviceUtils;
import com.demostic.demostic_test.utils.DialogUtils;
import com.demostic.demostic_test.utils.DisplayUtil;
import com.demostic.demostic_test.utils.MyLog;
import com.demostic.demostic_test.utils.SpUtils;
import com.demostic.demostic_test.utils.TimeUtil;
import com.demostic.demostic_test.utils.ToastUtils;
import com.google.gson.Gson;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.java_websocket.drafts.Draft_75;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

public class MapActivity_901 extends BaseActivity implements View.OnClickListener {
    public static final int START_AUTO_SCALE = 1;
    public static Point chPoint;
    public static Point hsPoint;
    public static boolean isAddVir = false;
    public static boolean isAutoScale;
    public static boolean isNeedQuery;
    public static boolean isPauseGetSlam;
    public static boolean isVirtualEdit;
    public static ArrayList<Integer> pointList;
    public static ArrayList<String> pointStrList;
    private final int CHECKROOM = 2;
    private final int CURMAP = 1;
    private final int DRAWAREA = 3;
    private final int QUEMAP = 2;
    private final int START = 2;
    private final int SUBCIRB = 1;
    private final String TAG = MapActivity_901.class.getSimpleName();
    private final int TAG_FVM = 1;
    private final int TAG_MAG = 4;
    private final int TAG_PAT = 2;
    private final int TAG_WHG = 3;
    private final int VIRFBD = 4;
    private ACDeviceMsg acDeviceMsg;
    Dialog alertDialog;
    private View anchorView;
    private int area;
    private int batteryCap;
    private Context context;
    private int curMapid;
    private MapView901 cvView;
    private long deviceId;
    private int editTag;
    private Dialog enterEdit;
    private Gson gson;
    private WeakHandler handler = new WeakHandler(new Handler.Callback() {
        /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass1 */

        @Override // android.os.Handler.Callback
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    MapActivity_901.isAutoScale = true;
                    return false;
                default:
                    return false;
            }
        }
    });
    private ImageView im_edit;
    private ImageView image_along;
    private ImageView image_back;
    private ImageView image_battery;
    private ImageView image_clock;
    private ImageView image_control;
    private ImageView image_gif;
    private ImageView image_keyPoint;
    private ImageView image_recharge;
    private ImageView image_setting;
    private ImageView image_start;
    private LayoutInflater inflater;
    private boolean isAlongWall;
    private boolean isCharging_cdz;
    private boolean isCharging_spq;
    private boolean isClickTab;
    private boolean isError;
    private boolean isExplore;
    private boolean isKeyPoint;
    private boolean isMaxMode;
    private boolean isPause;
    private boolean isRecharge;
    private boolean isRemote;
    private boolean isSleeping;
    private boolean isSleeping_cdz;
    private boolean isStandBy;
    private boolean isStart;
    private boolean isStopped;
    private boolean isTempKeyPoint;
    private boolean isThreeMap;
    private LinearLayout line_state;
    private ACDeviceMsg msg_workMode;
    private ACDeviceDataMgr.PropertyReceiver myPropertyReceiver;
    private HashMap<Integer, RoomNameInfo> nameList;
    private boolean noHistoryMap;
    private LinearLayout.LayoutParams params;
    private String physicalDeviceId;
    private PopupWindowWithMask popWnd_control;
    private PopupWindow popWnd_error;
    private RelativeLayout relativeLayout;
    private RelativeLayout rl_map;
    private ArrayList<Integer> rmidList;
    private Dialog saveMaptips;
    private Dialog selectDialog;
    private byte[] slamBytes;
    private String subdomain;
    private RelativeLayout tab_keyPoint;
    private RelativeLayout tab_recharge;
    private RelativeLayout tab_start;
    private int time;
    private Dialog tipsDialog;
    private TextView tv_area;
    private TextView tv_explore;
    private TextView tv_keyPoint;
    private TextView tv_recharge;
    private TextView tv_start;
    private TextView tv_state;
    private TextView tv_time;
    private int virual_switch;
    private int workMode;

    @Override // com.demostic.demostic_test.base.BaseActivity, android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        EventBus.getDefault().register(this);
        getDeviceInfo();
        initView();
        setListener();
        getDeviceType();
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.FragmentActivity, android.app.Activity
    public void onResume() {
        super.onResume();
        this.isStopped = false;
        getWorkStatus();
        initPropertyReceiver();
        registerPropertyReceiver();
        getDeviceProperty(0);
    }

    private void getDeviceType() {
        AC.deviceDataMgr().fetchCurrentProperty(this.subdomain, this.deviceId, new PayloadCallback<String>() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass2 */

            public void success(String s) {
                SpUtils.saveInt(MapActivity_901.this.context, "devType" + MapActivity_901.this.physicalDeviceId, ((DevicePropertyInfo_) MapActivity_901.this.gson.fromJson(s,  DevicePropertyInfo_.class)).getDevice_type());
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
            }
        });
    }

    private void getRooNameInfo(int curMapid2) {
        ACMsg acMsg = new ACMsg();
        acMsg.setName("getRoomInfo");
        acMsg.put("device_id", Long.valueOf(this.deviceId));
        acMsg.put("map_id", Integer.valueOf(curMapid2));
        AC.sendToService("", DeviceUtils.getServiceName(this.subdomain), 1, acMsg, new PayloadCallback<ACMsg>() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass3 */

            public void success(ACMsg resp) {
                MyLog.e(MapActivity_901.this.TAG, "getRooNameInfo success:" + resp);
                MapActivity_901.this.nameList.clear();
                if (resp.get("data") == null) {
                    MyLog.e(MapActivity_901.this.TAG, "getRooNameInfo data is null:");
                    return;
                }
                ArrayList<ACObject> data = (ArrayList) resp.get("data");
                if (data != null && data.size() > 0) {
                    String str = data.get(0).getString("room_info");
                    if (!TextUtils.isEmpty(str)) {
                        try {
                            JSONObject jsonObject = new JSONObject(str);
                            Iterator iterator = jsonObject.keys();
                            while (iterator.hasNext()) {
                                String key = (String) iterator.next();
                                JSONObject object = (JSONObject) jsonObject.get(key);
                                String name = object.getString("roomname");
                                JSONArray array = object.getJSONArray("namecoordinate");
                                RoomNameInfo info = new RoomNameInfo();
                                info.setRoomname(name);
                                if (array == null || array.length() <= 0) {
                                    info.setNamecoordinate(new int[0]);
                                } else {
                                    info.setNamecoordinate(new int[]{array.getInt(0), array.getInt(1)});
                                }
                                MapActivity_901.this.nameList.put(Integer.valueOf(key), info);
                                MyLog.e(MapActivity_901.this.TAG, "getPatitionName success data:" + key + "," + name + "," + MapActivity_901.this.nameList.size());
                            }
                            MapView901.setRoomName(MapActivity_901.this.nameList);
                            MapActivity_901.this.cvView.invalidate();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                MyLog.e(MapActivity_901.this.TAG, "getPatitionName error:" + e.toString());
            }
        });
    }

    public void initPropertyReceiver() {
        this.myPropertyReceiver = new ACDeviceDataMgr.PropertyReceiver() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass4 */

            @Override // com.accloud.service.ACDeviceDataMgr.PropertyReceiver
            public void onPropertyReceive(String s, long l, String s1) {
                if (!MapActivity_901.this.isStopped) {
                    MyLog.e(MapActivity_901.this.TAG, "dsdfdfs:" + s1);
                    PropertyInfo info = (PropertyInfo) MapActivity_901.this.gson.fromJson(s1,  PropertyInfo.class);
                    if (info != null) {
                        MapActivity_901.this.clearAll();
                        int errorCode = info.getError_info();
                        MapActivity_901.this.dealwithError(errorCode);
                        int workPattern = info.getWork_pattern();
                        MapActivity_901.this.workMode = workPattern;
                        MyLog.e(MapActivity_901.this.TAG, "initPropertyReceiver==:" + workPattern + "," + errorCode);
                        switch (workPattern) {
                            case 0:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_offline));
                                break;
                            case 1:
                                if (MapActivity_901.this.isError) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_device_error));
                                } else {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_sleep_));
                                }
                                MapActivity_901.this.isSleeping = true;
                                MapActivity_901.isPauseGetSlam = true;
                                break;
                            case 2:
                                MapActivity_901.this.isStandBy = true;
                                MapActivity_901.isPauseGetSlam = true;
                                if (!MapActivity_901.this.isError) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_standby_mode));
                                    break;
                                } else {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_device_error));
                                    break;
                                }
                            case 4:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_alongwall));
                                MapActivity_901.this.isAlongWall = true;
                                MapActivity_901.isPauseGetSlam = true;
                                break;
                            case 5:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_keyPoint_mode));
                                MapActivity_901.this.isKeyPoint = true;
                                break;
                            case 6:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_plan_mode));
                                MapActivity_901.this.isStart = true;
                                MyLog.e(MapActivity_901.this.TAG, "is clear map initPropertyReceiver:" + MapActivity_901.this.isStart);
                                break;
                            case 7:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_edit));
                                MapActivity_901.isVirtualEdit = true;
                                MapActivity_901.isPauseGetSlam = true;
                                break;
                            case 8:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_recharge_mode));
                                MapActivity_901.this.isRecharge = true;
                                break;
                            case 9:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_charge));
                                MapActivity_901.this.isCharging_cdz = true;
                                MapActivity_901.isPauseGetSlam = true;
                                break;
                            case 10:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_remotecontrol));
                                MapActivity_901.this.isRemote = true;
                                break;
                            case 11:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_charge));
                                MapActivity_901.this.isCharging_spq = true;
                                MapActivity_901.isPauseGetSlam = true;
                                break;
                            case 12:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_pause));
                                MapActivity_901.this.isPause = true;
                                break;
                            case 13:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_temp_focus));
                                MapActivity_901.this.isTempKeyPoint = true;
                                break;
                            case 15:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_explore));
                                MapActivity_901.this.isExplore = true;
                                break;
                            case 17:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_sleep));
                                MapActivity_901.this.isSleeping_cdz = true;
                                MapActivity_901.isPauseGetSlam = true;
                                break;
                            case 18:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_sleep));
                                MapActivity_901.this.isSleeping = true;
                                MapActivity_901.isPauseGetSlam = true;
                                break;
                            case 19:
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_explore));
                                MapActivity_901.this.isExplore = true;
                                break;
                        }
                        MapActivity_901.this.batteryCap = info.getBattery_level();
                        MapActivity_901.this.virual_switch = info.getLight_mode();
                        MapActivity_901.this.setBattery(MapActivity_901.this.batteryCap);
                        MapActivity_901.this.initStates(workPattern);
                        MapActivity_901.this.getChargePst(info.getCharger_position(), info.getRobot_position());
                        MapActivity_901.this.checkRoomid(1);
                        MapActivity_901.this.popWnd_control.setCurStatus(workPattern);
                        if (MapActivity_901.this.popWnd_control != null && !MapActivity_901.this.popWnd_control.isShowing()) {
                            MapActivity_901.this.setControlAndAlongWallStatus();
                        }
                        MapActivity_901.this.hidePopControl();
                    }
                }
            }
        };
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getChargePst(long charge_position, long robot_position) {
        int a = (int) charge_position;
        int chx = a >> 16;
        short chy = (short) a;
        if (Math.abs(chx) < 1500 && Math.abs((int) chy) < 1500) {
            chPoint.set(chx + 750, 750 - chy);
        }
        int b = (int) robot_position;
        int hsx = b >> 16;
        short hsy = (short) b;
        if (Math.abs(hsx) < 1500 && Math.abs((int) hsy) < 1500) {
            hsPoint.set(hsx + 750, 750 - hsy);
        }
        MyLog.e(this.TAG, "getChargePst charge point method= " + (chx + 750) + "," + (750 - chy) + "<->" + (hsx + 750) + "," + (750 - hsy) + "," + charge_position + "," + robot_position + ",");
    }

    private void registerPropertyReceiver() {
        AC.deviceDataMgr().subscribeProperty(this.subdomain, this.deviceId, new VoidCallback() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass5 */

            @Override // com.accloud.cloudservice.VoidCallback
            public void success() {
                AC.deviceDataMgr().registerPropertyReceiver(MapActivity_901.this.myPropertyReceiver);
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
            }
        });
    }

    private void getWorkStatus() {
        this.acDeviceMsg.setCode(65);
        this.acDeviceMsg.setContent(new byte[]{0});
        sendToDevice_WorkStatus(this.acDeviceMsg, this.physicalDeviceId);
    }

    private void getDeviceInfo() {
        this.context = this;
        this.physicalDeviceId = SpUtils.getSpString(this.context, "physicalDeviceId");
        this.subdomain = SpUtils.getSpString(this.context, "subdomain");
        this.deviceId = SpUtils.getLong(this.context, "deviceId");
        this.msg_workMode = new ACDeviceMsg();
        this.msg_workMode.setCode(70);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getEvent(TimeAreaInfo info) {
        this.area = info.getArea();
        this.time = info.getTime();
        if (this.isStart || isVirtualEdit || this.isPause) {
            setAreaAndTime();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getMapid(GetMapidMap info) {
        byte[] mapidbyte;
        MyLog.e(this.TAG, "get onReceive data robot_map_id getMapid:" + info.getS1());
        try {
            String st = new JSONObject(info.getS1()).getString("map_id");
            if (!TextUtils.isEmpty(st) && (mapidbyte = Base64.decode(st, 0)) != null && mapidbyte.length > 0) {
                int curMapid2 = DataUtils.getMapID(mapidbyte[0], mapidbyte[1], mapidbyte[2], mapidbyte[3]);
                if (curMapid2 != 0) {
                    if ((this.isStandBy || this.isCharging_cdz || this.isCharging_spq || this.isSleeping || this.isSleeping_cdz) && this.cvView.isHaveRoad()) {
                        this.cvView.clearRoad();
                    }
                    getRooNameInfo(curMapid2);
                    getRecordMap(curMapid2, 1, 0);
                } else {
                    this.cvView.clearMapidSlam();
                    this.cvView.invalidate();
                }
                MyLog.e(this.TAG, "jugeIsToClearMap success isclearmap==:" + mapidbyte.length + "," + curMapid2);
            }
        } catch (JSONException e) {
            MyLog.e(this.TAG, "JSONException e = " + e.toString());
            e.printStackTrace();
        }
    }

    private void initView() {
        isAutoScale = true;
        isPauseGetSlam = true;
        pointList = new ArrayList<>();
        pointStrList = new ArrayList<>();
        chPoint = new Point();
        hsPoint = new Point();
        this.nameList = new HashMap<>();
        this.gson = new Gson();
        this.acDeviceMsg = new ACDeviceMsg();
        ((TextView) findViewById(R.id.tv_title)).setText(getString(R.string.map_aty_title, new Object[]{"X901"}));
        this.inflater = LayoutInflater.from(this.context);
        this.popWnd_error = new PopupWindow(this.context);
        this.relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
        this.relativeLayout.setBackgroundColor(getResources().getColor(R.color.color_f2));
        this.rl_map = (RelativeLayout) findViewById(R.id.rl_map);
        this.image_gif = (ImageView) findViewById(R.id.image_gif);
        this.image_back = (ImageView) findViewById(R.id.image_back);
        this.image_setting = (ImageView) findViewById(R.id.image_setting);
        this.image_start = (ImageView) findViewById(R.id.image_start);
        this.image_recharge = (ImageView) findViewById(R.id.image_recharge);
        this.image_keyPoint = (ImageView) findViewById(R.id.image_key_point);
        this.anchorView = findViewById(R.id.view_);
        this.line_state = (LinearLayout) findViewById(R.id.line_state);
        this.line_state.setBackgroundColor(getResources().getColor(R.color.color_00bdb5));
        findViewById(R.id.view_status).setVisibility(8);
        findViewById(R.id.view_area).setVisibility(8);
        this.tv_state = (TextView) findViewById(R.id.tv_state);
        this.tv_area = (TextView) findViewById(R.id.tv_area);
        this.tv_time = (TextView) findViewById(R.id.tv_time);
        this.tv_state.setTextColor(getResources().getColor(R.color.status_color));
        ((TextView) findViewById(R.id.tv_state_)).setTextColor(getResources().getColor(R.color.status_color));
        this.tv_area.setTextColor(getResources().getColor(R.color.status_color));
        ((TextView) findViewById(R.id.tv_area_)).setTextColor(getResources().getColor(R.color.status_color));
        this.tv_time.setTextColor(getResources().getColor(R.color.status_color));
        ((TextView) findViewById(R.id.tv_time_)).setTextColor(getResources().getColor(R.color.status_color));
        this.tv_start = (TextView) findViewById(R.id.tv_start);
        this.tv_recharge = (TextView) findViewById(R.id.tv_recharge);
        this.tv_keyPoint = (TextView) findViewById(R.id.tv_keyPoint);
        this.tab_start = (RelativeLayout) findViewById(R.id.tab_start);
        this.tab_recharge = (RelativeLayout) findViewById(R.id.tab_recharge);
        this.tab_keyPoint = (RelativeLayout) findViewById(R.id.tab_keyPoint);
        this.cvView = new MapView901(this, this.deviceId, this.physicalDeviceId, this.subdomain, this.handler);
        this.params = new LinearLayout.LayoutParams(-1, -1);
        this.cvView.setLayoutParams(this.params);
        this.rl_map.addView(this.cvView);
        this.popWnd_control = new PopupWindowWithMask(this.context, this.relativeLayout, this.physicalDeviceId, this.subdomain);
        this.popWnd_control.setOnDismissListener(new PopupWindow.OnDismissListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass6 */

            @Override // android.widget.PopupWindow.OnDismissListener
            public void onDismiss() {
                MapActivity_901.this.setControlAndAlongWallStatus();
            }
        });
        initZoom();
    }

    public void initZoom() {
        this.image_battery = DisplayUtil.initRightZoom(this.context, this.relativeLayout, R.id.image_battery);
        this.image_battery.setImageResource(R.drawable.map_aty_battery4);
        this.image_clock = DisplayUtil.initRightZoom(this.context, this.relativeLayout, R.id.image_clock);
        this.image_clock.setImageResource(R.drawable.map_aty_clock_gray);
        this.im_edit = DisplayUtil.initRightZoom(this.context, this.relativeLayout, 2131755028);
        this.im_edit.setImageResource(R.drawable.edit_mode);
        this.image_control = DisplayUtil.initLeftZoom(this.context, this.relativeLayout, 2131755021, R.drawable.remote_gray);
        setControlStatus(false);
        this.image_along = DisplayUtil.initLeftZoom(this.context, this.relativeLayout, 2131755018, R.drawable.along_wall_disable);
        showMap();
    }

    private void setListener() {
        this.image_back.setOnClickListener(this);
        this.image_setting.setOnClickListener(this);
        this.tab_start.setOnClickListener(this);
        this.tab_recharge.setOnClickListener(this);
        this.tab_keyPoint.setOnClickListener(this);
        this.image_control.setOnClickListener(this);
        this.image_along.setOnClickListener(this);
        this.image_clock.setOnClickListener(this);
        this.im_edit.setOnClickListener(this);
    }

    @Override // android.view.View.OnClickListener
    public void onClick(View v) {
        switch (v.getId()) {
            case 2131755018 /* 2131755018 */:
                if (this.isStandBy || this.isPause || this.isRemote) {
                    this.msg_workMode.setContent(new byte[]{4});
                    sendToDevice_WorkStatus(this.msg_workMode, this.physicalDeviceId);
                    return;
                } else if (this.isAlongWall) {
                    this.msg_workMode.setContent(new byte[]{2});
                    sendToDevice_WorkStatus(this.msg_workMode, this.physicalDeviceId);
                    return;
                } else {
                    ToastUtils.showToast(this.context, getString(R.string.map_aty_can_not_execute));
                    return;
                }
            case R.id.image_clock /* 2131755020 */:
                //TODO
//                startActivity(new Intent(this, ClockingActivity_901.class));
                return;
            case 2131755021 /* 2131755021 */:
                if (this.popWnd_control != null) {
                    setControlStatus(false);
                    setAlongWallStatus(false);
                    this.popWnd_control.showAtLocation(this.relativeLayout, 17, 0, 0);
                    return;
                }
                return;
            case 2131755028 /* 2131755028 */:
                initSetVirtualDialog();
                return;
            case R.id.image_back /* 2131755189 */:
                if (this.image_gif != null) {
                    Glide.clear(this.image_gif);
                }
                finish();
                return;
            case R.id.image_setting /* 2131755294 */:
                //TODO
//                startActivity(new Intent(this.context, SettingActivity_900.class));
                return;
            case R.id.tab_recharge /* 2131755310 */:
                if (this.isCharging_cdz || this.isCharging_spq) {
                    ToastUtils.showToast(this.context, getString(R.string.map_aty_charging));
                    return;
                } else if (this.isKeyPoint || this.isAlongWall || this.isExplore || isVirtualEdit) {
                    ToastUtils.showToast(this.context, getString(R.string.map_aty_can_not_execute));
                    return;
                } else {
                    clickTab(R.id.tab_recharge);
                    return;
                }
            case R.id.tab_start /* 2131755313 */:
                if (this.isCharging_spq) {
                    ToastUtils.showToast(this.context, getString(R.string.map_aty_charging));
                    return;
                } else if (this.isRecharge || this.isKeyPoint) {
                    ToastUtils.showToast(this.context, getString(R.string.map_aty_can_not_execute));
                    return;
                } else {
                    clickTab_(R.id.tab_start);
                    return;
                }
            case R.id.tab_keyPoint /* 2131755316 */:
                if (this.isCharging_cdz || this.isCharging_spq) {
                    ToastUtils.showToast(this.context, getString(R.string.map_aty_charging));
                    return;
                } else if (this.isRecharge || this.isAlongWall || isVirtualEdit) {
                    ToastUtils.showToast(this.context, getString(R.string.map_aty_can_not_execute));
                    return;
                } else {
                    clickTab(R.id.tab_keyPoint);
                    return;
                }
            case R.id.rl_vir_fbd /* 2131755526 */:
                this.enterEdit.dismiss();
                if (this.virual_switch == 1) {
                    sendMapEditMode(1);
                    return;
                } else {
                    getDeviceProperty(4);
                    return;
                }
            case R.id.rl_patition /* 2131755528 */:
                this.enterEdit.dismiss();
                getDeviceProperty(2);
                return;
            case R.id.rl_wherego /* 2131755530 */:
                this.enterEdit.dismiss();
                getDeviceProperty(3);
                return;
            case R.id.rl_manage /* 2131755532 */:
                this.enterEdit.dismiss();
                if (this.isStandBy || this.isSleeping || this.isCharging_cdz || this.isSleeping_cdz) {
                    sendMapEditMode(4);
                    return;
                } else {
                    ToastUtils.showToast(this.context, getString(R.string.no_curmap));
                    return;
                }
            default:
                return;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showTipsDialog() {
        View view_tips = this.inflater.inflate(R.layout.dialog_patition_tips, (ViewGroup) null);
        this.tipsDialog = DialogUtils.showTipsDialog(this.context, view_tips);
        this.tipsDialog.setCanceledOnTouchOutside(false);
        this.tipsDialog.show();
        ((Button) view_tips.findViewById(R.id.bnt_know)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass7 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                MapActivity_901.this.tipsDialog.dismiss();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showSaveMapTipsDialog(int type) {
        View view_tips = this.inflater.inflate(R.layout.dialog_patition_tips, (ViewGroup) null);
        this.saveMaptips = DialogUtils.showTipsDialog(this.context, view_tips);
        this.saveMaptips.setCanceledOnTouchOutside(false);
        Button bnt_know = (Button) view_tips.findViewById(R.id.bnt_know);
        TextView tv_tips_type = (TextView) view_tips.findViewById(R.id.tv_tips_type);
        ((TextView) view_tips.findViewById(R.id.tv_tips_title)).setText(getString(R.string.save_map));
        tv_tips_type.setText(type == 4 ? getString(R.string.save_map_vir) : getString(R.string.save_map_));
        this.saveMaptips.show();
        bnt_know.setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass8 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                MapActivity_901.this.saveMaptips.dismiss();
            }
        });
    }

    private void initSetVirtualDialog() {
        View view_setvir = this.inflater.inflate(R.layout.dialog_edit_menu, (ViewGroup) null);
        this.enterEdit = DialogUtils.showSelectDialog(this.context, view_setvir, 1);
        this.enterEdit.show();
        ((RelativeLayout) view_setvir.findViewById(R.id.rl_vir_fbd)).setOnClickListener(this);
        ((RelativeLayout) view_setvir.findViewById(R.id.rl_manage)).setOnClickListener(this);
        ((RelativeLayout) view_setvir.findViewById(R.id.rl_patition)).setOnClickListener(this);
        ((RelativeLayout) view_setvir.findViewById(R.id.rl_wherego)).setOnClickListener(this);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void clearAll() {
        this.image_start.setSelected(false);
        this.image_recharge.setSelected(false);
        this.image_keyPoint.setSelected(false);
        this.tv_start.setSelected(false);
        this.tv_recharge.setSelected(false);
        this.tv_keyPoint.setSelected(false);
        this.isRecharge = false;
        this.isStart = false;
        this.isKeyPoint = false;
        this.isStandBy = false;
        this.isPause = false;
        this.isCharging_cdz = false;
        this.isCharging_spq = false;
        this.isTempKeyPoint = false;
        this.isSleeping = false;
        this.isSleeping_cdz = false;
        this.isRemote = false;
        this.isMaxMode = false;
        this.isError = false;
        this.isExplore = false;
        this.isAlongWall = false;
        isVirtualEdit = false;
        isPauseGetSlam = false;
        this.workMode = 0;
    }

    private void clickTab(int resId) {
        switch (resId) {
            case R.id.tab_recharge /* 2131755310 */:
                if (!this.isRecharge) {
                    this.msg_workMode.setContent(new byte[]{8});
                    break;
                } else {
                    this.msg_workMode.setContent(new byte[]{2});
                    break;
                }
            case R.id.tab_keyPoint /* 2131755316 */:
                if (!this.isKeyPoint) {
                    if (!this.isTempKeyPoint) {
                        this.msg_workMode.setContent(new byte[]{5});
                        break;
                    } else {
                        this.msg_workMode.setContent(new byte[]{6});
                        break;
                    }
                } else {
                    this.msg_workMode.setContent(new byte[]{2});
                    break;
                }
        }
        this.isClickTab = true;
        setAllUnClickable();
        sendToDevice_WorkStatus(this.msg_workMode, this.physicalDeviceId);
    }

    private void clickTab_(int resId) {
        switch (resId) {
            case R.id.tab_start /* 2131755313 */:
                if (!this.isStart) {
                    if (!this.isExplore) {
                        if (!this.isPause) {
                            if (!this.isAlongWall) {
                                checkRoomid(2);
                                break;
                            } else {
                                this.msg_workMode.setContent(new byte[]{2});
                                sendToDevice_WorkStatus(this.msg_workMode, this.physicalDeviceId);
                                break;
                            }
                        } else {
                            sendToClean();
                            break;
                        }
                    } else {
                        showStopExplore();
                        break;
                    }
                } else {
                    showSelectDialog();
                    break;
                }
        }
        this.isClickTab = true;
        setAllUnClickable();
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showExploreOrNewClean() {
        View view = LayoutInflater.from(this.context).inflate(R.layout.layout_explore_clean_dialog, (ViewGroup) null);
        final Dialog explore_clean = DialogUtils.showUnifyDialog(this.context, view);
        explore_clean.show();
        ((TextView) view.findViewById(R.id.tv_clean)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass9 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                explore_clean.dismiss();
                MapActivity_901.this.sendToClean();
            }
        });
        ((TextView) view.findViewById(R.id.tv_explore)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass10 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                explore_clean.dismiss();
                if (MapActivity_901.this.isThreeMap) {
                    MapActivity_901.this.showToMapManage();
                } else if (MapActivity_901.this.isCharging_cdz || MapActivity_901.this.isSleeping_cdz) {
                    MapActivity_901.this.msg_workMode.setContent(new byte[]{19});
                    MapActivity_901.this.sendToDevice_WorkStatus(MapActivity_901.this.msg_workMode, MapActivity_901.this.physicalDeviceId);
                } else {
                    ToastUtils.showToast(MapActivity_901.this.context, MapActivity_901.this.getString(R.string.set_robot_charging));
                    MapActivity_901.this.setAllClickable();
                }
            }
        });
        explore_clean.setOnCancelListener(new DialogInterface.OnCancelListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass11 */

            @Override // android.content.DialogInterface.OnCancelListener
            public void onCancel(DialogInterface dialog) {
                MapActivity_901.this.setAllClickable();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showToMapManage() {
        View view = LayoutInflater.from(this.context).inflate(R.layout.layout_to_manage_dialog, (ViewGroup) null);
        final Dialog dialog_manage = DialogUtils.showUnifyDialog(this.context, view);
        dialog_manage.show();
        TextView tv_dialog_confirm = (TextView) view.findViewById(R.id.tv_dialog_confirm);
        tv_dialog_confirm.setText(getString(R.string.to_delete));
        ((TextView) view.findViewById(R.id.tv_dialog_cancel)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass12 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                dialog_manage.dismiss();
                MapActivity_901.this.setAllClickable();
            }
        });
        tv_dialog_confirm.setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass13 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                dialog_manage.dismiss();
                //TODO
                MapActivity_901.this.setAllClickable();
                MapActivity_901.this.startActivity(new Intent(MapActivity_901.this, MapManageActivity901.class));
            }
        });
        dialog_manage.setOnCancelListener(new DialogInterface.OnCancelListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass14 */

            @Override // android.content.DialogInterface.OnCancelListener
            public void onCancel(DialogInterface dialog) {
                MapActivity_901.this.setAllClickable();
            }
        });
    }

    private void showStopExplore() {
        View view = LayoutInflater.from(this.context).inflate(R.layout.layout_explore_mode_dialog, (ViewGroup) null);
        final Dialog stopExploreDialog = DialogUtils.showUnifyDialog(this.context, view);
        stopExploreDialog.show();
        view.findViewById(R.id.tv_dialog_cancel).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass15 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                stopExploreDialog.dismiss();
                MapActivity_901.this.setAllClickable();
            }
        });
        view.findViewById(R.id.tv_dialog_confirm).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass16 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                stopExploreDialog.dismiss();
                MapActivity_901.this.msg_workMode.setContent(new byte[]{2});
                MapActivity_901.this.sendToDevice_WorkStatus(MapActivity_901.this.msg_workMode, MapActivity_901.this.physicalDeviceId);
            }
        });
        stopExploreDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass17 */

            @Override // android.content.DialogInterface.OnCancelListener
            public void onCancel(DialogInterface dialog) {
                MapActivity_901.this.setAllClickable();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void checkRoomid(final int type) {
        AC.deviceDataMgr().fetchCurrentProperty(this.subdomain, this.deviceId, new PayloadCallback<String>() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass18 */

            public void success(String s) {
                byte[] mapidbyte;
                boolean z = true;
                DevicePropertyInfo_ dataInfo = (DevicePropertyInfo_) MapActivity_901.this.gson.fromJson(s,  DevicePropertyInfo_.class);
                int roomId = dataInfo.getTarget_room_id();
                if (roomId != 0) {
                    MapActivity_901.this.rmidList = TimeUtil.getClockRoomID((byte) roomId);
                    MapActivity_901.this.setRoomID();
                } else if (MapView901.drawHm != null) {
                    MapView901.drawHm = DisplayUtil.getdrPainthm(MapActivity_901.this.context);
                }
                if (type == 2) {
                    String map_save = dataInfo.getMap_save();
                    if (!TextUtils.isEmpty(map_save) && (mapidbyte = Base64.decode(map_save, 0)) != null && mapidbyte.length > 0) {
                        int curMapid = DataUtils.getMapID(mapidbyte[0], mapidbyte[1], mapidbyte[2], mapidbyte[3]);
                        if (curMapid == 0 || (curMapid > 0 && !MapActivity_901.this.isSavedCurMap(mapidbyte, curMapid))) {
                            MapActivity_901.this.noHistoryMap = true;
                        } else {
                            MapActivity_901.this.noHistoryMap = false;
                        }
                        MapActivity_901 mapActivity_901 = MapActivity_901.this;
                        if (mapidbyte.length != 16) {
                            z = false;
                        }
                        mapActivity_901.isThreeMap = z;
                        MyLog.e(MapActivity_901.this.TAG, "dsfasf:" + curMapid + "," + MapActivity_901.this.isThreeMap + "," + MapActivity_901.this.isSavedCurMap(mapidbyte, curMapid) + "," + mapidbyte.length);
                    }
                    if (MapActivity_901.this.noHistoryMap) {
                        MapActivity_901.this.showExploreOrNewClean();
                    } else {
                        MapActivity_901.this.sendToClean();
                    }
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void sendToClean() {
        if (!this.isPause && this.batteryCap > 0 && this.batteryCap <= 6) {
            ToastUtils.showToast(this.context, getString(R.string.low_battery));
        }
        this.msg_workMode.setContent(new byte[]{6});
        sendToDevice_WorkStatus(this.msg_workMode, this.physicalDeviceId);
    }

    public void showSelectDialog() {
        View view = LayoutInflater.from(this.context).inflate(R.layout.layout_select_mode_dialog, (ViewGroup) null);
        final Dialog slectCleanDialog = DialogUtils.showUnifyDialog(this.context, view);
        slectCleanDialog.show();
        view.findViewById(R.id.tv_pause).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass19 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                slectCleanDialog.dismiss();
                MapActivity_901.this.msg_workMode.setContent(new byte[]{2});
                MapActivity_901.this.sendToDevice_WorkStatus(MapActivity_901.this.msg_workMode, MapActivity_901.this.physicalDeviceId);
            }
        });
        view.findViewById(R.id.tv_stop).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass20 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                slectCleanDialog.dismiss();
                MapActivity_901.this.msg_workMode.setContent(new byte[]{16});
                MapActivity_901.this.sendToDevice_WorkStatus(MapActivity_901.this.msg_workMode, MapActivity_901.this.physicalDeviceId);
            }
        });
        slectCleanDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass21 */

            @Override // android.content.DialogInterface.OnCancelListener
            public void onCancel(DialogInterface dialog) {
                MapActivity_901.this.setAllClickable();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showCleanOrSelect() {
        View view = LayoutInflater.from(this.context).inflate(R.layout.select_clean_dialog, (ViewGroup) null);
        this.selectDialog = DialogUtils.showUnifyDialog(this.context, view);
        this.selectDialog.show();
        this.selectDialog.setCanceledOnTouchOutside(false);
        view.findViewById(R.id.view_newclean).setVisibility(8);
        ((TextView) view.findViewById(R.id.tv_new_clean)).setVisibility(8);
        ((TextView) view.findViewById(R.id.tv_select_map)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass22 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                //TODO
                MapActivity_901.this.selectDialog.dismiss();
                MapActivity_901.this.startActivity(new Intent(MapActivity_901.this, MapManageActivity901.class));
            }
        });
        ((TextView) view.findViewById(R.id.tv_select_cancle)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass23 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                MapActivity_901.this.selectDialog.dismiss();
                MapActivity_901.this.setAllClickable();
            }
        });
    }

    public void setBatteryImage(int batteryCap2) {
        DisplayUtil.setBatteryImage(batteryCap2, this.image_battery);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void sendMapEditMode(int tag) {
        LogUtil.d("sendMapEditMode-->" + tag);
        if (tag == 2 || tag == 3) {
            Intent intent = new Intent(this, MapEditActivity901.class);
            intent.putExtra("EDIT_TAG", tag);
            startActivity(intent);
        } else if (tag == 4) {
            //TODO
            Intent intent2 = new Intent(this, MapManageActivity901.class);
            intent2.putExtra("CurrentMapid", this.curMapid);
            intent2.putExtra("ChargeBaseX", chPoint.x);
            intent2.putExtra("ChargeBaseY", chPoint.y);
            startActivity(intent2);
        } else {
            this.acDeviceMsg.setCode(90);
            this.acDeviceMsg.setContent(new byte[]{1});
            sendToDevice_WorkStatus(this.acDeviceMsg, this.physicalDeviceId);
        }
        isVirtualEdit = true;
        isPauseGetSlam = true;
        this.editTag = tag;
    }

    public void sendToDevice_WorkStatus(ACDeviceMsg deviceMsg, final String physicalDeviceId2) {
        AC.bindMgr().sendToDeviceWithOption(this.subdomain, physicalDeviceId2, deviceMsg, 2, new PayloadCallback<ACDeviceMsg>() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass24 */

            public void success(ACDeviceMsg deviceMsg) {
                if (!MapActivity_901.this.isStopped) {
                    switch (deviceMsg.getCode()) {
                        case 65:
                            byte[] byte_decStatus = deviceMsg.getContent();
                            SpUtils.saveInt(MapActivity_901.this.context, "devType" + physicalDeviceId2, byte_decStatus[9] & Draft_75.END_OF_FRAME);
                            MapActivity_901.this.getChargePosition(byte_decStatus);
                            MapActivity_901.this.getRoomId(byte_decStatus);
                            MapActivity_901.this.clearAll();
                            MapActivity_901.this.dealwithError(byte_decStatus[8] & Draft_75.END_OF_FRAME);
                            byte workStatus_ = byte_decStatus[0];
                            MapActivity_901.this.workMode = workStatus_;
                            if (workStatus_ == 0) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_offline));
                            } else if (workStatus_ == 1) {
                                if (MapActivity_901.this.isError) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_device_error));
                                } else {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_sleep));
                                }
                                MapActivity_901.this.isSleeping = true;
                                MapActivity_901.isPauseGetSlam = true;
                            } else if (workStatus_ == 2) {
                                if (MapActivity_901.this.isError) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_device_error));
                                } else {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_standby_mode));
                                }
                                MapActivity_901.this.isStandBy = true;
                                MapActivity_901.isPauseGetSlam = true;
                            } else if (workStatus_ == 4) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_alongwall));
                                MapActivity_901.this.isAlongWall = true;
                                MapActivity_901.isPauseGetSlam = true;
                            } else if (workStatus_ == 5) {
                                MapActivity_901.this.isKeyPoint = true;
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_keyPoint_mode));
                            } else if (workStatus_ == 6) {
                                MapActivity_901.this.isStart = true;
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_plan_mode));
                            } else if (workStatus_ == 7) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_edit));
                                MapActivity_901.isVirtualEdit = true;
                                MapActivity_901.isPauseGetSlam = true;
                            } else if (workStatus_ == 8) {
                                MapActivity_901.this.isRecharge = true;
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_recharge_mode));
                            } else if (workStatus_ == 9) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_charge));
                                MapActivity_901.this.isCharging_cdz = true;
                                MapActivity_901.isPauseGetSlam = true;
                            } else if (workStatus_ == 10) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_remote));
                                MapActivity_901.this.isRemote = true;
                            } else if (workStatus_ == 11) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_charge));
                                MapActivity_901.this.isCharging_spq = true;
                                MapActivity_901.isPauseGetSlam = true;
                            } else if (workStatus_ == 12) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_pause));
                                MapActivity_901.this.isPause = true;
                            } else if (workStatus_ == 13) {
                                MapActivity_901.this.isTempKeyPoint = true;
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_temp_focus));
                            } else if (workStatus_ == 14) {
                                //TODO
//                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_update));
//                                MapActivity_901.this.startActivity(new Intent(MapActivity_901.this, OtaUpdateActivity.class));
                            } else if (workStatus_ == 15) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_explore));
                                MapActivity_901.this.isExplore = true;
                            } else if (workStatus_ == 17) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_sleep));
                                MapActivity_901.this.isSleeping_cdz = true;
                                MapActivity_901.isPauseGetSlam = true;
                            } else if (workStatus_ == 18) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_sleep));
                                MapActivity_901.this.isSleeping = true;
                                MapActivity_901.isPauseGetSlam = true;
                            } else if (workStatus_ == 19) {
                                MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_explore));
                                MapActivity_901.this.isExplore = true;
                            }
                            byte clockinfo = byte_decStatus[1];
                            if (clockinfo == 0) {
                                MapActivity_901.this.image_clock.setImageResource(R.drawable.map_aty_clock_gray);
                            } else if (clockinfo == 1) {
                                MapActivity_901.this.image_clock.setImageResource(R.drawable.map_aty_clock);
                            }
                            MapActivity_901.this.batteryCap = byte_decStatus[5];
                            MapActivity_901.this.virual_switch = byte_decStatus[7];
                            SpUtils.saveInt(MapActivity_901.this.context, physicalDeviceId2 + "batteryCap", MapActivity_901.this.batteryCap);
                            MapActivity_901.this.setBattery(MapActivity_901.this.batteryCap);
                            MapActivity_901.this.popWnd_control.setCurStatus(workStatus_);
                            MapActivity_901.this.initStates(workStatus_);
                            break;
                        case 70:
                            byte[] resp_wokeMode = deviceMsg.getContent();
                            if (resp_wokeMode != null && resp_wokeMode.length == 1) {
                                MapActivity_901.this.clearAll();
                                byte workStatus = resp_wokeMode[0];
                                MapActivity_901.this.workMode = workStatus;
                                if (workStatus == 2) {
                                    MapActivity_901.this.isStandBy = true;
                                } else if (workStatus == 4) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_alongwall));
                                    MapActivity_901.this.isAlongWall = true;
                                } else if (workStatus == 5) {
                                    MapActivity_901.this.isKeyPoint = true;
                                } else if (workStatus == 6) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_plan_mode));
                                    MapActivity_901.this.isStart = true;
                                } else if (workStatus == 7) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_edit));
                                    MapActivity_901.isVirtualEdit = true;
                                } else if (workStatus == 8) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_recharge_mode));
                                    MapActivity_901.this.isRecharge = true;
                                } else if (workStatus == 9) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_charge));
                                    MapActivity_901.this.isCharging_cdz = true;
                                    ToastUtils.showToast(MapActivity_901.this.context, MapActivity_901.this.getString(R.string.map_aty_charging));
                                } else if (workStatus == 10) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_remote));
                                    MapActivity_901.this.isRemote = true;
                                } else if (workStatus == 12) {
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_pause));
                                    MapActivity_901.this.isPause = true;
                                } else if (workStatus == 13) {
                                    MapActivity_901.this.isTempKeyPoint = true;
                                    MapActivity_901.this.tv_state.setText(MapActivity_901.this.getString(R.string.map_aty_temp_focus));
                                }
                                MapActivity_901.this.popWnd_control.setCurStatus(workStatus);
                                MapActivity_901.this.setAllClickable();
                                MapActivity_901.this.initStates(workStatus);
                                break;
                            } else {
                                return;
                            }
                        case 90:
                            Intent intent = new Intent(MapActivity_901.this, MapEditActivity901.class);
                            intent.putExtra("EDIT_TAG", MapActivity_901.this.editTag);
                            intent.putExtra("work_mode", MapActivity_901.this.workMode);
                            MapActivity_901.this.startActivity(intent);
                            break;
                    }
                    MapActivity_901.this.setRoomID();
                    MapActivity_901.this.setControlAndAlongWallStatus();
                } else if (MapActivity_901.this.isClickTab) {
                    MapActivity_901.this.isClickTab = false;
                    MapActivity_901.this.setAllClickable();
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                MyLog.e(MapActivity_901.this.TAG, "set or getWorkStatus error e " + e.toString());
                ToastUtils.showErrorToast(MapActivity_901.this.context, e.getErrorCode());
                if (MapActivity_901.this.isClickTab) {
                    MapActivity_901.this.isClickTab = false;
                    MapActivity_901.this.setAllClickable();
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setBattery(int batteryCap2) {
        if (!this.isCharging_cdz && !this.isCharging_spq) {
            setBatteryImage(batteryCap2);
        } else if (batteryCap2 >= 98) {
            this.image_battery.setImageResource(R.drawable.map_aty_charge_full);
        } else {
            this.image_battery.setImageResource(R.drawable.map_aty_charging);
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getRoomId(byte[] btStatus) {
        int bt0 = btStatus[21] << 24;
        int bt1 = btStatus[22] << 16;
        int id = bt0 + bt1 + (btStatus[23] << 8) + btStatus[24];
        MyLog.e(this.TAG, "test room id getWorkStatus:" + id);
        this.rmidList = TimeUtil.getClockRoomID((byte) id);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getChargePosition(byte[] bytes) {
        int hsx = DataUtils.bytesToInt(new byte[]{bytes[12], bytes[13]}, 0);
        int hsy = DataUtils.bytesToInt(new byte[]{bytes[14], bytes[15]}, 0);
        int hostX = hsx + 750;
        int hostY = 1500 - (hsy + 750);
        int chargX = DataUtils.bytesToInt(new byte[]{bytes[16], bytes[17]}, 0) + 750;
        int chargY = 1500 - (DataUtils.bytesToInt(new byte[]{bytes[18], bytes[19]}, 0) + 750);
        if (Math.abs(hostX) < 1500 && Math.abs(hostY) < 1500) {
            hsPoint.set(hostX, hostY);
        }
        if (Math.abs(chargX) < 1500 && Math.abs(chargY) < 1500) {
            chPoint.set(chargX, chargY);
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setRoomID() {
        if (this.rmidList != null && this.rmidList.size() > 0) {
            int size = this.rmidList.size();
            for (int i = 0; i < size; i++) {
                int id = this.rmidList.get(i).intValue();
                MyLog.e(this.TAG, "fdsdfsdfaccc:" + id);
                if (!(MapView901.drawHm == null || MapView901.hms == null)) {
                    MapView901.drawHm.get(Integer.valueOf(id - 10)).setColor(MapView901.hms.get(Integer.valueOf(id - 10)).getColor());
                }
            }
        }
    }

    private void getDeviceProperty(final int queryType) {
        AC.deviceDataMgr().fetchCurrentProperty(this.subdomain, this.deviceId, new PayloadCallback<String>() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass25 */

            public void success(String s) {
                byte[] mapidbyte;
                DevicePropertyInfo_ dataInfo = (DevicePropertyInfo_) MapActivity_901.this.gson.fromJson(s,  DevicePropertyInfo_.class);
                MapActivity_901.this.getChargePst(dataInfo.getCharger_position(), dataInfo.getRobot_position());
                String map_save = dataInfo.getMap_save();
                if (!TextUtils.isEmpty(map_save) && (mapidbyte = Base64.decode(map_save, 0)) != null && mapidbyte.length > 0) {
                    MapActivity_901.this.curMapid = DataUtils.getMapID(mapidbyte[0], mapidbyte[1], mapidbyte[2], mapidbyte[3]);
                    MyLog.e(MapActivity_901.this.TAG, "test clear map getDeviceProperty:" + queryType + "," + MapActivity_901.this.curMapid);
                    if (queryType == 2 || queryType == 3) {
                        if (!MapActivity_901.this.isSleeping && !MapActivity_901.this.isStandBy && !MapActivity_901.this.isCharging_cdz && !MapActivity_901.this.isSleeping_cdz) {
                            ToastUtils.showToast(MapActivity_901.this.context, MapActivity_901.this.getString(R.string.no_work_mode));
                        } else if (MapActivity_901.this.curMapid == 0) {
                            if (MapActivity_901.this.isHasHistory(mapidbyte)) {
                                MapActivity_901.this.showCleanOrSelect();
                            } else {
                                MapActivity_901.this.showTipsDialog();
                            }
                        } else if (MapActivity_901.this.isSavedCurMap(mapidbyte, MapActivity_901.this.curMapid)) {
                            MapActivity_901.this.getRecordMap(MapActivity_901.this.curMapid, 2, queryType);
                        } else {
                            MapActivity_901.this.showSaveMapTipsDialog(queryType);
                        }
                    } else if (queryType != 4) {
                        MapActivity_901.this.getRecordMap(MapActivity_901.this.curMapid, 1, 0);
                    } else if (MapActivity_901.this.curMapid == 0) {
                        ToastUtils.showToast(MapActivity_901.this.context, MapActivity_901.this.getString(R.string.vir_unenble));
                    } else if (!MapActivity_901.this.isSavedCurMap(mapidbyte, MapActivity_901.this.curMapid)) {
                        MapActivity_901.this.showSaveMapTipsDialog(queryType);
                    }
                    MyLog.e(MapActivity_901.this.TAG, "getDeviceProperty success:" + mapidbyte.length + "," + MapActivity_901.this.curMapid);
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                MyLog.e(MapActivity_901.this.TAG, "getDeviceProperty error==:" + e.toString());
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private boolean isHasHistory(byte[] bt) {
        int length = bt.length;
        for (int i = 4; i < length; i += 4) {
            if (DataUtils.getMapID(bt[i], bt[i + 1], bt[i + 2], bt[i + 3]) != 0) {
                return true;
            }
        }
        return false;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private boolean isSavedCurMap(byte[] bt, int curMapid2) {
        int length = bt.length;
        for (int i = 4; i < length; i += 4) {
            if (DataUtils.getMapID(bt[i], bt[i + 1], bt[i + 2], bt[i + 3]) == curMapid2) {
                return true;
            }
        }
        return false;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getRecordMap(int mapid, final int type, final int queryType) {
        ACMsg acMsg = new ACMsg();
        acMsg.setName("getRecordMap");
        acMsg.put("device_id", Long.valueOf(this.deviceId));
        acMsg.put("map_id", Integer.valueOf(mapid));
        AC.sendToService("", DeviceUtils.getServiceName(this.subdomain), 1, acMsg, new PayloadCallback<ACMsg>() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass26 */

            public void success(ACMsg resp) {
                MyLog.e(MapActivity_901.this.TAG, "getRecordMap success:" + resp.toString());
                if (resp.get("data") != null) {
                    ACObject acObject = (ACObject) ((ArrayList) resp.get("data")).get(0);
                    String strMap = acObject.getString("clean_slam");
                    LogUtil.d("strMap->" + strMap);
                    String roadData = acObject.getString("clean_road");
                    if (type == 1) {
                        int xMax = acObject.getInt("slam_x_max");
                        int xMin = acObject.getInt("slam_x_min");
                        int yMax = acObject.getInt("slam_y_max");
                        int yMin = acObject.getInt("slam_y_min");
                        if (!TextUtils.isEmpty(strMap)) {
                            MapActivity_901.this.slamBytes = Base64.decode(strMap, 0);
                        }
                        if (!TextUtils.isEmpty(roadData)) {
                            Point lp = DataUtils.getLastPoint(Base64.decode(roadData, 0));
                            if (MapActivity_901.chPoint.x == 0 && MapActivity_901.chPoint.y == 0) {
                                MapActivity_901.chPoint.set(lp.x, lp.y);
                                MapActivity_901.hsPoint.set(lp.x, lp.y);
                                MyLog.e(MapActivity_901.this.TAG, "charge point raod:" + lp.x + "," + lp.y);
                            }
                        }
                        MapActivity_901.this.cvView.setEditData(MapActivity_901.this.slamBytes, xMax, xMin, yMax, yMin);
                    } else if (type != 2) {
                    } else {
                        if (TextUtils.isEmpty(strMap)) {
                            MapActivity_901.this.showCleanOrSelect();
                        } else if (queryType == 2) {
                            MapActivity_901.this.sendMapEditMode(2);
                        } else if (queryType == 3) {
                            MapActivity_901.this.sendMapEditMode(3);
                        }
                    }
                } else if (type == 2) {
                    MapActivity_901.this.showCleanOrSelect();
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                MyLog.e(MapActivity_901.this.TAG, "getRecordMap error:" + e.toString());
            }
        });
    }

    public void initStates(int workmode) {
        boolean z;
        boolean z2;
        boolean z3;
        boolean z4 = true;
        this.tv_start.setText((this.isStart || this.isExplore || this.isAlongWall) ? getString(R.string.map_aty_stop_clean) : getString(R.string.map_aty_start_clean));
        if (this.isStandBy) {
            this.tv_start.setText(getString(R.string.map_aty_start_clean));
        } else if (this.isStart || this.isExplore || this.isAlongWall) {
            this.tv_start.setText(getString(R.string.map_aty_stop_clean));
        }
        ImageView imageView = this.image_start;
        if (this.isStart || this.isExplore || this.isAlongWall) {
            z = true;
        } else {
            z = false;
        }
        imageView.setSelected(z);
        TextView textView = this.tv_start;
        if (this.isStart || this.isExplore || this.isAlongWall) {
            z2 = true;
        } else {
            z2 = false;
        }
        textView.setSelected(z2);
        this.image_recharge.setSelected(this.isRecharge);
        this.tv_recharge.setSelected(this.isRecharge);
        ImageView imageView2 = this.image_keyPoint;
        if (this.isKeyPoint || this.isTempKeyPoint) {
            z3 = true;
        } else {
            z3 = false;
        }
        imageView2.setSelected(z3);
        TextView textView2 = this.tv_keyPoint;
        if (!this.isKeyPoint && !this.isTempKeyPoint) {
            z4 = false;
        }
        textView2.setSelected(z4);
        if (this.isStart || isVirtualEdit || this.isPause) {
            setAreaAndTime();
        } else {
            setAreaAndTimeEmpty();
        }
        if (workmode == 19) {
            if (this.tv_explore != null) {
                this.tv_explore.setVisibility(0);
            } else {
                setTextExplore();
            }
        } else if (this.tv_explore != null) {
            this.tv_explore.setVisibility(8);
        }
    }

    private void setTextExplore() {
        this.tv_explore = new TextView(this.context);
        this.tv_explore.setId(2131296576);
        this.tv_explore.setText(getString(R.string.explore_text));
        this.tv_explore.setTextColor(SupportMenu.CATEGORY_MASK);
        this.tv_explore.setTextSize(10.0f);
        this.tv_explore.setGravity(17);
        this.tv_explore.getPaint().setFlags(1);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(-2, -2);
        this.relativeLayout.addView(this.tv_explore);
        lp.addRule(12);
        lp.addRule(13);
        lp.addRule(1);
        lp.addRule(0, R.id.image_battery);
        lp.addRule(1, 2131755021);
        lp.bottomMargin = DisplayUtil.dip2px(this.context, 20.0f);
        lp.rightMargin = DisplayUtil.dip2px(this.context, 10.0f);
        lp.leftMargin = DisplayUtil.dip2px(this.context, 10.0f);
        this.tv_explore.setLayoutParams(lp);
    }

    private void setAreaAndTimeEmpty() {
        this.tv_area.setText("——");
        this.tv_time.setText("——");
    }

    private void setAreaAndTime() {
        if (this.area == 0 && this.time == 0) {
            setAreaAndTimeEmpty();
            return;
        }
        this.tv_area.setText((((double) this.area) / 100.0d) + "㎡");
        this.tv_time.setText((this.time / 60) + "min");
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void dealwithError(int errorCode) {
        if (errorCode != 0) {
            this.isError = true;
            if (!this.popWnd_error.isShowing()) {
                showErrorPopup(errorCode);
            }
        } else if (this.popWnd_error.isShowing()) {
            this.popWnd_error.dismiss();
        }
    }

    private void showErrorPopup(int errorCode) {
        View contentView = LayoutInflater.from(this.context).inflate(R.layout.popup_error, (ViewGroup) null);
        initErrorPopup(errorCode, contentView);
        this.popWnd_error.setBackgroundDrawable(new ColorDrawable(0));
        this.popWnd_error.setContentView(contentView);
        this.popWnd_error.setOutsideTouchable(false);
        this.popWnd_error.setFocusable(false);
        this.popWnd_error.setWidth(-1);
        this.popWnd_error.setHeight(-2);
        this.popWnd_error.showAsDropDown(this.anchorView);
    }

    public void initErrorPopup(int errorCode, View contentView) {
        DeviceUtils.setErroeText(this.context, errorCode, (TextView) contentView.findViewById(R.id.tv_error));
        ((ImageView) contentView.findViewById(R.id.image_delete)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.activity.MapActivity_901.AnonymousClass27 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                if (MapActivity_901.this.popWnd_error != null) {
                    MapActivity_901.this.popWnd_error.dismiss();
                }
            }
        });
    }

    public void showMap() {
        this.image_gif.setVisibility(8);
        this.rl_map.setVisibility(0);
    }

    public void setControlAndAlongWallStatus() {
        if (this.isRecharge || this.isKeyPoint || this.isStart || this.isAlongWall || this.isSleeping || this.isSleeping_cdz || this.isCharging_cdz || this.isCharging_spq || this.isError) {
            setControlStatus(false);
        } else if (this.isStandBy || this.isRemote) {
            setControlStatus(true);
        }
        if (this.isRecharge || this.isKeyPoint || this.isStart || this.isAlongWall || this.isRemote || this.isSleeping || this.isSleeping_cdz || this.isCharging_cdz || this.isCharging_spq || this.isError) {
            setAlongWallStatus(false);
        } else if (this.isStandBy) {
            setAlongWallStatus(true);
        }
    }

    public void setControlStatus(boolean isClickable) {
        this.image_control.setImageResource(isClickable ? R.drawable.map_aty_dir_clickable_ : R.drawable.remote_gray);
        this.image_control.setClickable(isClickable);
    }

    public void setAlongWallStatus(boolean enable) {
        this.image_along.setImageResource(enable ? R.drawable.along_wall_enable : R.drawable.along_wall_disable);
        this.image_along.setClickable(enable);
    }

    public void setAllClickable() {
        this.tab_start.setClickable(true);
        this.tab_keyPoint.setClickable(true);
        this.tab_recharge.setClickable(true);
    }

    public void setAllUnClickable() {
        this.tab_start.setClickable(false);
        this.tab_keyPoint.setClickable(false);
        this.tab_recharge.setClickable(false);
    }

    public void hidePopControl() {
        if ((this.isStart || this.isKeyPoint || this.isRecharge) && this.popWnd_control != null && this.popWnd_control.isShowing()) {
            this.popWnd_control.dismiss();
        }
    }

    /* access modifiers changed from: protected */
    @Override // com.demostic.demostic_test.base.BaseActivity, android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onStop() {
        super.onStop();
        this.isStopped = true;
        if (this.popWnd_error != null && this.popWnd_error.isShowing()) {
            this.popWnd_error.dismiss();
        }
    }

    @Override // android.support.v4.app.FragmentActivity, android.app.Activity
    public void onBackPressed() {
        if (this.popWnd_error == null || !this.popWnd_error.isShowing()) {
            super.onBackPressed();
        } else {
            this.popWnd_error.dismiss();
        }
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        super.onDestroy();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }
}
